//
//  ZXFDCreateClassView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/19.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZXFDCreateClassView.h"
#import "SYRequestAPI+FuDao.h"
#import "SYRequestAPI+TongYong.h"
#import "FenXiaoZhuJiaoModel.h"
#import "FuDaoLeiXingObject.h"
#import "SYRequestAPI+HomePage.h"
#import "BRPickerView.h"
#import "SYTutoringSelectView.h"


@interface ZXFDCreateClassView ()
@property (strong, nonatomic) SYTutoringSelectView *tutoringView;
@property (assign, nonatomic) BOOL isOk;//是否是线下辅导过了

@end



@implementation ZXFDCreateClassView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    _zhuJiaoArray = [NSMutableArray new];
    _fuDaoTypeArray = [NSMutableArray new];
    _fuDaoTimesArray = [NSMutableArray new];
    
    [self addSubview:self.navView];
    [self addSubview:self.classNameTF];
    [self addSubview:self.classNameLabel];
    [self addSubview:self.lineView];
    
    [self addSubview:self.mentorTF];
    [self addSubview:self.mentorLabel];
    [self addSubview:self.lineView2];
    
    [self addSubview:self.zhuJiaoLabel];
    [self addSubview:self.selectedZhuJiaoView];
    
    [self addSubview:self.fuDaoTypeView];
    [self addSubview:self.fuDaoTypeLabel];
    
    //考试view
    [self addSubview:self.kaoshiView];
    //考试lab
    [self.kaoshiView addSubview:self.kaoshiLab];
    //考试
    [self.kaoshiView addSubview:self.kaoshiSelectedView];
    
    // 辅导类型
    
    [self addSubview:self.fuDaoNewView];
    [self addSubview:self.fuDaoNewLabel];
    
    
    [self addSubview:self.fuDaoTimesView];
    [self addSubview:self.fuDaoTimesLabel];
    
//    [self addSubview:self.jieZhiRiQiLabel];
//    [self addSubview:self.kaiShiTimeView];
//    [self addSubview:self.jierShuTimeView];
//
//    [self addSubview:self.fuDaioContentLabel];
//    [self addSubview:self.fuDaiContentTV];
    
    [self addSubview:self.commitBtn];
    //选中是否是辅导过了
    [self addSubview:self.tutoringView];
    //得到教师信息
    [self getCurrentTeacherInfor];
    [self setFuDaoTypeRequest];
    
    [self addNoticeForKebord];
    
}
- (void)layout{
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    [_classNameTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-30);
        make.top.equalTo(@74);
        make.height.equalTo(@25);
        make.width.equalTo(@0).offset(270);
    }];
    [_classNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_classNameTF.mas_left).offset(-10);
        make.width.equalTo(@100);
        make.top.equalTo(self->_classNameTF.mas_top);
        make.height.equalTo(@15);
    }];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_classNameTF.mas_left);
        make.right.equalTo(self->_classNameTF.mas_right);
        make.height.equalTo(@1);
        make.top.equalTo(self->_classNameTF.mas_bottom);
    }];
    
    [_mentorTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-30);
        make.top.equalTo(self->_lineView.mas_bottom).offset(40);
        make.height.equalTo(@15);
        make.width.equalTo(@0).offset(270);
    }];
    [_mentorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_mentorTF.mas_left).offset(-10);
        make.width.equalTo(@100);
        make.top.equalTo(self->_mentorTF.mas_top);
        make.height.equalTo(@15);
    }];
    [_lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_mentorTF.mas_left);
        make.right.equalTo(self->_mentorTF.mas_right);
        make.height.equalTo(@1);
        make.top.equalTo(self->_mentorTF.mas_bottom);
    }];
    
    [_selectedZhuJiaoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-30);
        make.top.equalTo(self->_lineView2.mas_bottom).offset(40);
        make.height.equalTo(@30);
        make.width.equalTo(@0).offset(270);
    }];
    [_zhuJiaoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.right.equalTo(self->_selectedZhuJiaoView.mas_left).offset(-10);
        make.height.equalTo(@15);
        make.centerY.equalTo(self->_selectedZhuJiaoView.mas_centerY);
    }];
    
    [_fuDaoTypeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-30);
        make.top.equalTo(self->_zhuJiaoLabel.mas_bottom).offset(40);
        make.height.equalTo(@30);
        make.width.equalTo(@0).offset(270);
    }];
    //考试
    [_kaoshiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self->_fuDaoTypeView.mas_centerY);
        make.left.equalTo(self->_fuDaoTypeView.mas_right).offset(10);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(200);
    }];
    //考试标题
    [_kaoshiLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.top.equalTo(self.kaoshiView);
    }];
    //考试选择
    [_kaoshiSelectedView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self->_kaoshiLab.mas_centerY);
        make.left.equalTo(self->_kaoshiLab.mas_right).offset(10);
        //make.right.equalTo(self->_kaoshiView.mas_right);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(150);
    }];
    
    
    
    [_fuDaoTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.right.equalTo(self->_fuDaoTypeView.mas_left).offset(-10);
        make.height.equalTo(@15);
        make.centerY.equalTo(self->_fuDaoTypeView.mas_centerY);
    }];
    [_fuDaoNewView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-30);
        make.top.equalTo(self->_fuDaoTypeLabel.mas_bottom).offset(40);
        make.height.equalTo(@30);
        make.width.equalTo(@0).offset(270);
    }];
    [_fuDaoNewLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.right.equalTo(self->_fuDaoNewView.mas_left).offset(-10);
        make.height.equalTo(@15);
        make.centerY.equalTo(self->_fuDaoNewView.mas_centerY);
    }];
    [_fuDaoTimesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-30);
        make.top.equalTo(self->_fuDaoNewLabel.mas_bottom).offset(40);
        make.height.equalTo(@30);
        make.width.equalTo(@0).offset(270);
    }];
    [_fuDaoTimesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@100);
        make.right.equalTo(self->_fuDaoTimesView.mas_left).offset(-10);
        make.height.equalTo(@15);
        make.centerY.equalTo(self->_fuDaoTimesView.mas_centerY);
    }];
    
//    [_jieZhiRiQiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self->_fuDaoTimesLabel.mas_left);
//        make.right.equalTo(self->_fuDaoTimesLabel.mas_right);
//        make.top.equalTo(self->_fuDaoTimesLabel.mas_bottom).offset(40);
//        make.height.equalTo(@30);
//    }];
//    [_kaiShiTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self->_fuDaoTimesView.mas_left);
//        make.width.equalTo(@130);
//        make.centerY.equalTo(self->_jieZhiRiQiLabel.mas_centerY);
//        make.height.equalTo(@30);
//    }];
//    [_jierShuTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self->_kaiShiTimeView.mas_right).offset(10);
//        make.width.equalTo(@130);
//        make.centerY.equalTo(self->_jieZhiRiQiLabel.mas_centerY);
//        make.height.equalTo(@30);
//    }];
//
//    [_fuDaiContentTV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self->_fuDaoTimesView.mas_left);
//        make.right.equalTo(self->_fuDaoTimesView.mas_right);
//        make.top.equalTo(self->_jierShuTimeView.mas_bottom).offset(40);
//        make.height.equalTo(@100);
//    }];
//    [_fuDaioContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self->_jieZhiRiQiLabel.mas_right);
//        make.left.equalTo(self->_jieZhiRiQiLabel.mas_left);
//        make.top.equalTo(self->_fuDaiContentTV.mas_top);
//        make.height.equalTo(@30);
//    }];
    
    [_commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX).offset(-30);
//        make.top.equalTo(self.mas_bottom).offset(40);
        make.bottom.equalTo(self.mas_bottom).offset(-200);
        make.height.equalTo(@40);
        make.width.equalTo(@130);
    }];
    //是否是线下辅导过了
    [_tutoringView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_fuDaoNewView.mas_right).offset(10);
        make.centerY.equalTo(self.fuDaoNewView.mas_centerY).offset(0);
        make.width.mas_equalTo(150);
        make.height.mas_equalTo(40);
    }];
    __weak typeof(self) weakSelf = self;
    _tutoringView.block = ^(BOOL isSelect) {//yes 是
        weakSelf.isOk = isSelect;
    };
    
}

- (void)setIsXiu:(BOOL)isXiu {
    _isXiu = isXiu;
    if (isXiu == YES) {
        self.navView.titleLabe.text = @"修改编辑信息";
    } else {
        self.navView.titleLabe.text = @"创建班级";
    }
}

- (void)setClassName:(NSString *)className {
    _className = className;
    NSString *string = [NSString stringWithFormat:@"%@%@",className,[NSString getNowDate]];
    self.classNameTF.text = string;
    _selectedZhuJiaoView.nameLabel.text = _fdbjName;
    tutorAccountId = _fdbjId;//班级id
    
}
//辅导缘由
- (void)fuDaoYuanYou {
    if (_className) {
        //辅导缘由
        for (FuDaoLeiXingObject *fdModel in _fuDaoTypeArray) {
            if ([fdModel.name containsString:_className]) {
                self.fuDaoTypeView.nameLabel.text = fdModel.name;
                self->type = fdModel.fudaoID;
                [self selectFuDaoYuanYouModel:fdModel];
                break;
            }
        }
    }
}

- (SYTutoringSelectView *)tutoringView {
    if (!_tutoringView) {
        _tutoringView = [[NSBundle mainBundle] loadNibNamed:@"SYTutoringSelectView" owner:nil options:nil].firstObject;
        _tutoringView.hidden = YES;
    }
    return _tutoringView;
}


- (ZXFDCCVNav *)navView{
    if (!_navView) {
        ZXFDCCVNav *view = [[ZXFDCCVNav alloc]init];
        view.backgroundColor = MAINBACKCOLOR;
        view.delegate = self;
        _navView = view;
    }
    return _navView;
}
- (void)backClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(self.frame.size.width,0, self.frame.size.width, self.frame.size.height);
    }completion:^(BOOL finished) {
        [[NSNotificationCenter defaultCenter] postNotificationName:kNotification object:nil];
        [self removeFromSuperview];
    }];
}
//班级名称
- (UILabel *)classNameLabel{
    if (!_classNameLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"班级名称:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _classNameLabel = label;
    }
    return _classNameLabel;
}
- (UITextField *)classNameTF{
    if (!_classNameTF) {
        UITextField *tf = [[UITextField alloc]init];
        tf.font = [UIFont systemFontOfSize:12];
        tf.textColor = TITLECOLOR;
        tf.delegate = self;
        _classNameTF = tf;
    }
    return _classNameTF;
}
- (UIView *)lineView{
    if (!_lineView) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = LINCOLOR;
        _lineView = view;
    }
    return _lineView;
}
//辅导老师
- (UILabel *)mentorLabel{
    if (!_mentorLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"辅导老师:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _mentorLabel = label;
    }
    return _mentorLabel;
}
//教师列表没有
- (UITextField *)mentorTF{
    if (!_mentorTF) {
        UITextField *tf = [[UITextField alloc]init];
        tf.font = [UIFont systemFontOfSize:12];
        tf.textColor = TITLECOLOR;
        tf.userInteractionEnabled = NO;
        _mentorTF = tf;
    }
    return _mentorTF;
}
- (void)selectedTeacher{
    
}
#pragma mark - 得到当前的登录教师信息
- (void)getCurrentTeacherInfor{
    NSDictionary *responseObject = [USERDEFAL objectForKey:UserInforModelDefalut];
    self->_userInfoModel = [UserInformationModel yy_modelWithJSON:[responseObject objectForKey:@"data"]];
    _mentorTF.text = self->_userInfoModel.name;
}
- (UIView *)lineView2{
    if (!_lineView2) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = LINCOLOR;
        _lineView2 = view;
    }
    return _lineView2;
}
//班级
- (UILabel *)zhuJiaoLabel{
    if (!_zhuJiaoLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"选择班级:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _zhuJiaoLabel = label;
    }
    return _zhuJiaoLabel;
}
- (ZXFDCSelectedView *)selectedZhuJiaoView{
    if (!_selectedZhuJiaoView) {
        ZXFDCSelectedView *view = [[ZXFDCSelectedView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        view.layer.cornerRadius = 2;
        view.layer.borderColor = [UIColorChange colorwithHexString:@"#999999"].CGColor;
        view.layer.borderWidth = 1;
        view.nameLabel.text = @"选择班级";
        view.selected = NO;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedMentor:)];
        [view addGestureRecognizer:tap];
        _selectedZhuJiaoView = view;
    }
    return _selectedZhuJiaoView;
}
#pragma 助教弹出选择框
- (void)selectedMentor:(UITapGestureRecognizer *)tap{
    _selectedZhuJiaoView.selected = !_selectedZhuJiaoView.selected;
    currentView = _selectedZhuJiaoView;
    if (_selectedZhuJiaoView.selected == YES) {
        [self alertView];
        //得到分校助教
        _selectedAlertView.type = 1;
        [self getFenXiaoZhuJiaoRequest];
        [self addSubview:_selectedAlertView];
        [_selectedAlertView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_selectedZhuJiaoView.mas_centerX);
            make.top.equalTo(self->_selectedZhuJiaoView.mas_bottom);
            make.width.equalTo(self->_selectedZhuJiaoView.mas_width);
            make.height.equalTo(@150);
        }];
    }else{
      //  NSLog(@"删除0");
        [_selectedAlertView removeFromSuperview];
        _selectedAlertView = nil;
    }

}
//辅导u缘由
- (UILabel *)fuDaoTypeLabel{
    if (!_fuDaoTypeLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"辅导缘由:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _fuDaoTypeLabel = label;
    }
    return _fuDaoTypeLabel;
}
- (ZXFDCSelectedView *)fuDaoTypeView{
    if (!_fuDaoTypeView) {
        ZXFDCSelectedView *view = [[ZXFDCSelectedView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        view.layer.cornerRadius = 2;
        view.layer.borderColor = [UIColorChange colorwithHexString:@"#999999"].CGColor;
        view.layer.borderWidth = 1;
        view.nameLabel.text = @"选择辅导缘由";
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedFuDaoType)];
        [view addGestureRecognizer:tap];
        _fuDaoTypeView = view;
        
    }
    return _fuDaoTypeView;
}
- (void)selectedFuDaoType{
    if (self->tutorAccountId.length == 0) {
        [XSInfoView showInfo:@"请先选择班级" onSubView:self];
        return;
    }
    currentView = _fuDaoTypeView;
    _fuDaoTypeView.selected = !_fuDaoTypeView.selected;
    if (_fuDaoTypeView.selected == YES) {
        [self alertView];
        [_selectedAlertView reloadData];
        [self addSubview:_selectedAlertView];
        _selectedAlertView.dataArray = _fuDaoTypeArray;
        _selectedAlertView.type = 2;
        [_selectedAlertView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_fuDaoTypeView.mas_centerX);
            make.top.equalTo(self->_fuDaoTypeView.mas_bottom);
            make.width.equalTo(self->_fuDaoTypeView.mas_width);
            make.height.equalTo(@150);
        }];
    }else{
       // NSLog(@"删除0");
        [_selectedAlertView removeFromSuperview];
        _selectedAlertView = nil;
    }
}
//考试view
- (UIView *)kaoshiView {
    if (!_kaoshiView) {
        _kaoshiView = [[UIView alloc] init];
        _kaoshiView.hidden = YES;
    }
    return _kaoshiView;
}
- (UILabel *)kaoshiLab {
    if (!_kaoshiLab) {
        _kaoshiLab = [UILabel titleColour:TITLECOLOR
                               titleFount:14
                                 pingfang:@"PingFang-SC-Regular"
                                alignment:2
                                titleLine:1];
        _kaoshiLab.text = @"关联考试:";
    }
    return _kaoshiLab;
}
//考试选择
- (ZXFDCSelectedView *)kaoshiSelectedView {
    if (!_kaoshiSelectedView) {
        _kaoshiSelectedView = [[ZXFDCSelectedView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        _kaoshiSelectedView.layer.cornerRadius = 2;
        _kaoshiSelectedView.layer.borderColor = [UIColorChange colorwithHexString:@"#999999"].CGColor;
        _kaoshiSelectedView.layer.borderWidth = 1;
        _kaoshiSelectedView.nameLabel.text = @"选择考试卷";
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectKaoShiTap)];
        [_kaoshiSelectedView addGestureRecognizer:tap];
        
    }
    return _kaoshiSelectedView;
}

//辅导类型
-(UILabel *)fuDaoNewLabel{
    if (!_fuDaoNewLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"辅导类型:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _fuDaoNewLabel = label;
    }
    return _fuDaoNewLabel;
}
- (ZXFDCSelectedView *)fuDaoNewView{
    if (!_fuDaoNewView) {
        ZXFDCSelectedView *view = [[ZXFDCSelectedView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        view.layer.cornerRadius = 2;
        view.layer.borderColor = [UIColorChange colorwithHexString:@"#999999"].CGColor;
        view.layer.borderWidth = 1;
        view.nameLabel.text = @"选择辅导类型";
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedFuDaoTyView)];
        [view addGestureRecognizer:tap];
        _fuDaoNewView = view;
    }
    return _fuDaoNewView;
}
//辅导次数
- (UILabel *)fuDaoTimesLabel{
    if (!_fuDaoTimesLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"辅导次数:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _fuDaoTimesLabel = label;
    }
    return _fuDaoTimesLabel;
}
- (ZXFDCSelectedView *)fuDaoTimesView{
    if (!_fuDaoTimesView) {
        ZXFDCSelectedView *view = [[ZXFDCSelectedView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        view.layer.cornerRadius = 2;
        view.layer.borderColor = [UIColorChange colorwithHexString:@"#999999"].CGColor;
        view.layer.borderWidth = 1;
        view.nameLabel.text = @"选择辅导次数";
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedFuDaoTimesView)];
        [view addGestureRecognizer:tap];
        _fuDaoTimesView = view;
    }
    return _fuDaoTimesView;
}
-(NSMutableArray *)fuDaoTyArray{

    if (!_fuDaoTyArray) {
        _fuDaoTyArray = [NSMutableArray array];
        NSDictionary *dic1 = @{@"name":@"互动课堂",@"typeId":@"0"};
        [_fuDaoTyArray addObject:dic1];
        NSDictionary *dic2 = @{@"name":@"群聊",@"typeId":@"1"};
        [_fuDaoTyArray addObject:dic2];
        NSDictionary *dic3 = @{@"name":@"单聊",@"typeId":@"2"};
        [_fuDaoTyArray addObject:dic3];

    }
    return _fuDaoTyArray;
}
-(void)selectedFuDaoTyView{
    currentView = _fuDaoNewView;
    _fuDaoNewView.selected = !_fuDaoNewView.selected;
    if (_fuDaoNewView.selected == YES) {
        [self alertView];
        _selectedAlertView.type = 5;
        _selectedAlertView.dataArray = self.fuDaoTyArray;
        [_selectedAlertView reloadData];
        [self addSubview:_selectedAlertView];
        [_selectedAlertView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_fuDaoNewView.mas_centerX);
            make.top.equalTo(self->_fuDaoNewView.mas_bottom);
            make.width.equalTo(self->_fuDaoNewView.mas_width);
            make.height.equalTo(@150);
        }];
    }else{
        //  NSLog(@"删除0");
        [_selectedAlertView removeFromSuperview];
        _selectedAlertView = nil;
    }
}
//[XSInfoView showInfo:error.domain onSubView:self];
- (void)selectedFuDaoTimesView{
    if (isChat==YES) {
        [MBProgressHUD zr_showError:@"群聊/单聊不需要设置辅导次数"];
        return;
    }
    currentView = _fuDaoTimesView;
    _fuDaoTimesView.selected = !_fuDaoTimesView.selected;
    if (_fuDaoTimesView.selected == YES) {
        [self alertView];
        _selectedAlertView.type = 3;
        _selectedAlertView.dataArray = _fuDaoTimesArray;
        [_selectedAlertView reloadData];
        [self addSubview:_selectedAlertView];
        [_selectedAlertView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_fuDaoTimesView.mas_centerX);
            make.top.equalTo(self->_fuDaoTimesView.mas_bottom);
            make.width.equalTo(self->_fuDaoTimesView.mas_width);
            make.height.equalTo(@150);
        }];
    }else{
      //  NSLog(@"删除0");
        [_selectedAlertView removeFromSuperview];
        _selectedAlertView = nil;
    }
}
#pragma mark - 考试
//考试
- (void)selectKaoShiTap {
    _kaoshiSelectedView.selected =!_kaoshiSelectedView.selected;
    if (_kaoshiSelectedView.selected == YES) {
        [self alertView];
        
        _selectedAlertView.type = 4;
       // _selectedAlertView.dataArray = _fuDaoTimesArray;
        [_selectedAlertView reloadData];
        [self addSubview:_selectedAlertView];
        [_selectedAlertView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self->_kaoshiSelectedView.mas_centerX);
            make.top.equalTo(self->_kaoshiSelectedView.mas_bottom);
            make.width.equalTo(self->_kaoshiSelectedView.mas_width);
            make.height.equalTo(@150);
        }];
        self.selectedAlertView.dataArray = self.kaoshiArr;
        [self->_selectedAlertView reloadData];
    } else {
        [_selectedAlertView removeFromSuperview];
        _selectedAlertView = nil;
    }
}

//截止日期
- (UILabel *)jieZhiRiQiLabel{
    if (!_jieZhiRiQiLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"起止日期:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _jieZhiRiQiLabel = label;
    }
    return _jieZhiRiQiLabel;
}
- (ZXFDCSelectedView *)kaiShiTimeView{
    if (!_kaiShiTimeView) {
        ZXFDCSelectedView *view = [[ZXFDCSelectedView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        view.layer.cornerRadius = 2;
        view.layer.borderColor = [UIColorChange colorwithHexString:@"#999999"].CGColor;
        view.layer.borderWidth = 1;
        view.nameLabel.text = @"开始日期";
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedKaiShiTimeView)];
        [view addGestureRecognizer:tap];
        _kaiShiTimeView = view;
    }
    return _kaiShiTimeView;
}
- (void)selectedKaiShiTimeView{
    
    if (isChat == YES) {
        [MBProgressHUD zr_showError:@"群聊/单聊不需要设置日期"];
        return;
    }
    
    
    
    
    [BRDatePickerView showDatePickerWithTitle:@"开始日期" dateType:BRDatePickerModeDateAndTime defaultSelValue:nil minDate:nil maxDate:nil isAutoSelect:NO themeColor:[UIColor colorWithHexString:@"0x20B097"] view:self.fuDaoTypeView resultBlock:^(NSString *selectValue) {
        
        if (self->endDate.length != 0) {
            NSInteger index  = [NSObject compareOneDay:[NSObject dateFormatter:self->endDate] withAnotherDay:[NSObject dateFormatter:selectValue]];
            if (index == -1) {
                
                [XSInfoView showInfo:@"结束日期不能再开始日期之前" onSubView:self];
                return ;
            }
        }
        
        self->_kaiShiTimeView.nameLabel.text = selectValue;
        self->beginDate = selectValue;
        
        
    }];
    
    
//    [DatePickerView setDatePickerViewWithFrame:self.frame andTitle:@"开始日期" andSuccessBlock:^(NSString * _Nonnull dateString) {
//       // NSLog(@"选择日期 %@",dateString);
//        if (self->endDate.length != 0) {
//            NSInteger index  = [NSObject compareOneDay:[NSObject dateFormatter:self->endDate] withAnotherDay:[NSObject dateFormatter:dateString]];
//            if (index == -1) {
//
//                [XSInfoView showInfo:@"结束日期不能再开始日期之前" onSubView:self];
//                return ;
//            }
//        }
//
//        self->_kaiShiTimeView.nameLabel.text = dateString;
//        self->beginDate = dateString;
//    }];
}
- (ZXFDCSelectedView *)jierShuTimeView{
    if (!_jierShuTimeView) {
        ZXFDCSelectedView *view = [[ZXFDCSelectedView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        view.layer.cornerRadius = 2;
        view.layer.borderColor = [UIColorChange colorwithHexString:@"#999999"].CGColor;
        view.layer.borderWidth = 1;
        view.nameLabel.text = @"结束日期";
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectedJierShuTimeView)];
        [view addGestureRecognizer:tap];
        _jierShuTimeView = view;
    }
    return _jierShuTimeView;
}
- (void)selectedJierShuTimeView{
    if (isChat == YES) {
        [MBProgressHUD zr_showError:@"群聊/单聊不需要设置日期"];
        return;
    }
    if (self->beginDate.length == 0) {
        [XSInfoView showInfo:@"请选择开始日期" onSubView:self];
        return;
    }
    
    [BRDatePickerView showDatePickerWithTitle:@"结束日期" dateType:BRDatePickerModeDateAndTime defaultSelValue:nil minDate:nil maxDate:nil isAutoSelect:NO themeColor:[UIColor colorWithHexString:@"0x20B097"] view:self.fuDaoTypeView resultBlock:^(NSString *selectValue) {
        
        NSInteger index  = [NSObject compareOneDay:[NSObject dateFormatter:selectValue] withAnotherDay:[NSObject dateFormatter:self->beginDate]];
        if (index == -1) {
            
            [XSInfoView showInfo:@"结束日期不能再开始日期之前" onSubView:self];
            return ;
        }
        
        self->_jierShuTimeView.nameLabel.text = selectValue;
        self->endDate =  selectValue;
        
        
    }];
    
//    [DatePickerView setDatePickerViewWithFrame:self.frame andTitle:@"结束日期" andSuccessBlock:^(NSString * _Nonnull dateString) {
//       // NSLog(@"选择日期 %@",dateString); dateString
//        NSInteger index  = [NSObject compareOneDay:[NSObject dateFormatter:dateString] withAnotherDay:[NSObject dateFormatter:self->beginDate]];
//        if (index == -1) {
//
//            [XSInfoView showInfo:@"结束日期不能再开始日期之前" onSubView:self];
//            return ;
//        }
//
//        self->_jierShuTimeView.nameLabel.text = dateString;
//        self->endDate =  dateString;
//    }];
}
//辅导内容
- (UILabel *)fuDaioContentLabel{
    if (!_fuDaioContentLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"辅导内容:";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 2;
        _fuDaioContentLabel = label;
    }
    return _fuDaioContentLabel;
}
- (UITextView *)fuDaiContentTV{
    if (!_fuDaiContentTV) {
        UITextView *tv = [[UITextView alloc]init];
        tv.textColor = TITLECOLOR;
        tv.font = [UIFont systemFontOfSize:12];
        tv.layer.cornerRadius = 2;
        tv.layer.borderWidth = 1;
        tv.editable = NO;
        tv.layer.borderColor = LINCOLOR.CGColor;
        tv.layer.masksToBounds = YES;
        tv.delegate = self;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tvTap:)];
        [tv addGestureRecognizer:tap];
        _fuDaiContentTV = tv;
    }
    return _fuDaiContentTV;
}
- (void)tvTap:(UITapGestureRecognizer *)tap{
    [editeView removeFromSuperview];
    [[UIApplication sharedApplication].keyWindow.rootViewController.view addSubview:[self AddEditeView]];
}
- (UIButton *)commitBtn{
    if (!_commitBtn) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"下一步" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds  =YES;
        button.layer.borderColor = SELECTEDCOLOR.CGColor;
        button.layer.borderWidth = 1;
        [button addTarget:self action:@selector(commitBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        _commitBtn = button;
    }
    return _commitBtn;
}
- (void)commitBtnClick:(UIButton *)sender{
    [self getChuangJianBnJiRequest];
   
    //创建班级
}
- (void)alertView{
    _selectedAlertView = [[ZCFDCreateClassTableView alloc]initWithFrame:CGRectMake(0, 0, 0, 150) style:UITableViewStyleGrouped];
    _selectedAlertView.backgroundColor = [UIColor whiteColor];
    _selectedAlertView.layer.borderWidth = 1;
    _selectedAlertView.layer.cornerRadius = 1;
    _selectedAlertView.layer.borderColor = SELECTEDCOLOR.CGColor;
    _selectedAlertView.layer.masksToBounds = YES;
    /*
     选择列表选项
     
     @param indexPath 行数
     @param type 1：助教 2：辅导类型 3：辅导次数 4:考试
     @return haha
    */
    __weak typeof(self) weakSelf = self;
    _selectedAlertView.block = ^(NSIndexPath * _Nonnull indexPath, int type) {
       // NSLog(@"输出选择的Index %ld",(long)indexPath.row);
        if (type == 1) {
            //选择班级
            FenXiaoZhuJiaoModel *model = weakSelf.zhuJiaoArray[indexPath.row];
            weakSelf.selectedZhuJiaoView.nameLabel.text = model.name;
            self->tutorAccountId = model.classId;//[NSString stringWithFormat:@"%ld",(long)indexPath.row];
            
        }else if (type == 2){
            FuDaoLeiXingObject *model = weakSelf.fuDaoTypeArray[indexPath.row];
            weakSelf.fuDaoTypeView.nameLabel.text = model.name;
            self->type = model.fudaoID;
            [weakSelf selectFuDaoYuanYouModel:model];
        }else if (type == 3){
            self->tutorTimes = [NSString stringWithFormat:@"%ld",(long)indexPath.row+1];
            weakSelf.fuDaoTimesView.nameLabel.text = [NSString stringWithFormat:@"辅导%@次",self->tutorTimes];
            weakSelf.fuDaoTimesView.selected  = NO;
        } else if (type == 4) {//考试
            SYKaoShiModel *kaoshi = self.kaoshiArr[indexPath.row];
            weakSelf.kaoshiSelectedView.nameLabel.text = kaoshi.title;
            weakSelf.kaoshiId = kaoshi.templateId;
            //存储考试id
            SaveDataToNSUserDefaults(kaoshi.templateId, kKaoShiId);
        }else if (type == 5){
            NSLog(@"%@",self.fuDaoTyArray);
            NSDictionary *dic = self.fuDaoTyArray[indexPath.row];
            NSString *fdtypeStr = dic[@"name"];
            if ([fdtypeStr isEqualToString:@"单聊"]||[fdtypeStr isEqualToString:@"群聊"]) {
                self->isChat = YES;
            } else {
                self-> isChat = NO;
            }
            weakSelf.fuDaoNewView.nameLabel.text = dic[@"name"];
            weakSelf.FDTypeId = dic[@"typeId"];
        }
    };
}
#pragma mark - 选择了辅导缘由
- (void)selectFuDaoYuanYouModel:(FuDaoLeiXingObject *)model {
    if ([model.name containsString:@"前三"]||[model.name containsString:@"后三名"]) {
        self.kaoshiView.hidden = NO;
        
        [self requestListArrKaoshi];
        if ([model.name containsString:@"后三名"]) {
            SaveDataToNSUserDefaults(@"后三名", kKaoShiType);
        } else {
            self.tutoringView.hidden = NO;//错题率前三才能课堂辅导
        }
    } else {
        if ([model.name containsString:@"成绩异常"]) {
            SaveDataToNSUserDefaults(@"成绩异常", kKaoShiType);
        } else if ([model.name containsString:@"出勤异常"]) {
            SaveDataToNSUserDefaults(@"出勤异常", kKaoShiType);
        } else {
            //删除考试id
            DeleteDataFromNSUserDefaults(kKaoShiId);
            DeleteDataFromNSUserDefaults(kKaoShiType);
        }
        self.kaoshiView.hidden = YES;
        self.tutoringView.hidden = YES;
        self.kaoshiId = @"0";
        
    }
}


//请求考试接口
- (void)requestListArrKaoshi {
    __weak typeof(self) weakSelf = self;
    [MBProgressHUD mj_showMessage:nil toView:self];
    [SYRequestAPI fd_getTemplateInfoByClassId:self->tutorAccountId success:^(NSMutableArray *datalistArr) {
        [MBProgressHUD mj_hideHUDForView:self];
        weakSelf.kaoshiArr = datalistArr;
        
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self];
    }];
    
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
    NSArray * array2 = [touches allObjects];
    UITouch *touch = [array2 lastObject];
    
    if (touch.view == currentView) {
        
    }else{
        [_selectedAlertView removeFromSuperview];
        _selectedZhuJiaoView.selected = NO;
        _fuDaoTimesView.selected = NO;
        _fuDaoTypeView.selected = NO;
    }
   // NSLog(@"当前Touches的视图 %@",touch.view);
    
    
}


//@param fdId 辅导班级 必填,添加传0，否则传ID
//@param title 辅导班级名称
//@param classId 班级ID
//@param accountId 辅导老师
//@param tutorAccountId 班级id
//@param type 辅导类型
//@param tutorTimes 辅导次数
//@param beginDate 开始日期
//@param endDate 结束日期
//@param content 辅导内容
#pragma mark - 创建班级
- (void)getChuangJianBnJiRequest{
    
    title = _classNameTF.text;//班级名
    content = _fuDaiContentTV.text.length > 0 ? _fuDaiContentTV.text:@"";//辅导内容
    acountID = _userInfoModel.accountId;
    if (acountID.length == 0) {
        acountID = @"1";
    }
    
    if (self.isXiu == YES) {//修改
        //传入辅导id
        fdId = self.fdId;
    } else {
        fdId = @"0";//添加
    }
    
    
    classID = @"0";//固定传0
    if (title.length == 0) {
        [XSInfoView showInfo:@"请输入班级名称" onSubView:self];
        return;
    }
    if (tutorAccountId.length<=0) {
        [XSInfoView showInfo:@"请选择班级" onSubView:self];
        return;
    }
    if (self.FDTypeId == nil) {
        [XSInfoView showInfo:@"请选择辅导类型" onSubView:self];
        return;
    }
    if (isChat == NO) {
        if (tutorTimes.length<=0) {
            [XSInfoView showInfo:@"请选择辅导次数" onSubView:self];
            return;
        }
//        if (beginDate.length<=0) {
//            [XSInfoView showInfo:@"请选择开始日期" onSubView:self];
//            return;
//        }
//        if (endDate.length<=0) {
//            [XSInfoView showInfo:@"请选择结束日期" onSubView:self];
//            return;
//        }
    } else {
        tutorTimes = @"";
        beginDate = @"";
        endDate = @"";
    }
//    if (type.length <=0) {
//        [XSInfoView showInfo:@"请选择辅导缘由" onSubView:self];
//        return;
//    }
    
    beginDate = beginDate.length >0 ? beginDate : @"";
    endDate = endDate.length > 0 ? endDate : @"";
    
    
    NSString *msgId = nil;
    if (self.mesgId.length > 0) {
        msgId = self.mesgId;
    } else {
        msgId = @"0";
    }
    NSString *finished = self.isOk == YES?@"1":@"0";
    
    
    
    //存储班级id
    SaveDataToNSUserDefaults(self->tutorAccountId, kKaoShiClassId);
    [MBProgressHUD mj_showMessage:nil toView:self];
    [SYRequestAPI fd_requestZaiXianAddFuDaoClassId:fdId title:title classId:tutorAccountId accountId:acountID tutorAccountId:self.kaoshiId type:type tutorType:self.FDTypeId tutorTimes:tutorTimes beginDate:beginDate endDate:endDate content:content msgId:msgId isFinished:finished success:^(id responseObject) {
        SaveDataToNSUserDefaults(self->_selectedZhuJiaoView.nameLabel.text, @"banjimingcheng");
        SaveDataToNSUserDefaults(self->beginDate, @"kaishishijian");
        SaveDataToNSUserDefaults(self->endDate, @"jieshushijian");
        SaveDataToNSUserDefaults(self->title, @"banjiname");//班级名字
        NSString * fdID = [[responseObject objectForKey:@"data"] objectForKey:@"id"];
        
        
        
        
      //  NSLog(@"创建班级成功 %@",responseObject);
        if (self.isXiu) {//修改班级
             [XSInfoView showInfo:@"修改成功" onSubView:self];
            [NSString executeRunloop:^{
                [self backClick];
            } afterDelay:2];
            
        } else {
            
            if (self.isOk) {
                [MBProgressHUD zr_showError:@"保存成功"];
                [NSString executeRunloop:^{
                    [self backClick];
                } afterDelay:1.5];
            } else {
                if ([self.FDTypeId integerValue] > 0) {
                    [self addSubview:self.xueShengView];
                    self.xueShengView.fdID = fdID;
                    [self->_xueShengView mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.left.equalTo(@0);
                        make.top.equalTo(@0);
                        make.right.equalTo(@0);
                        make.bottom.equalTo(@0);
                    }];
                    return ;
                }
                //            self->_selectedZhuJiaoView.nameLabel.text 班级名称
                
                //前往选择课时
                self->_keShiXuanZeView = [[XuanZeKeShiVC alloc]init];
                self->_keShiXuanZeView.fuDaoTimesInt = [self->tutorTimes intValue];
                self->_keShiXuanZeView.classID = fdID;
                self->_keShiXuanZeView.className = self->title;
                self->_keShiXuanZeView.teacherName = self->_userInfoModel.name;
                self->_keShiXuanZeView.teacheType = self->_fuDaoTypeView.nameLabel.text ;
                self->_keShiXuanZeView.view.frame = CGRectMake(self.frame.size.width, 0, self.frame.size.width, self.frame.size.height);
                [self addSubview:self->_keShiXuanZeView.view];
                [self->_keShiXuanZeView.view mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(@0);
                    make.right.equalTo(@0);
                    make.top.equalTo(@0);
                    make.bottom.equalTo(@0);
                }];
                [self->_keShiXuanZeView.tableList reloadData];
                
                
                
                //             测试成绩后三，成绩异常
                //            [self addSubview:self.xueShengView];
                //            [self->_xueShengView mas_makeConstraints:^(MASConstraintMaker *make) {
                //                make.left.equalTo(@0);
                //                make.top.equalTo(@0);
                //                make.right.equalTo(@0);
                //                make.bottom.equalTo(@0);
                //            }];
                
                
            }
            
            [MBProgressHUD mj_hideHUDForView:self];
            }
            
           
    } fail:^(NSError *error) {
        [XSInfoView showInfo:error.domain onSubView:self];
        [MBProgressHUD mj_hideHUDForView:self];
    }];
    
}
- (ZaiXianFuDaoTianJiaXueShengView *)xueShengView{
    if (!_xueShengView) {
        ZaiXianFuDaoTianJiaXueShengView *view = [[ZaiXianFuDaoTianJiaXueShengView alloc]init];
        _xueShengView = view;
    }
    return _xueShengView;
}
#pragma mark - 得到分校助教
//是否考虑全部请求到数据？？？
- (void)getFenXiaoZhuJiaoRequest{
    
    if (self.zhuJiaoArray.count > 0) {
        self->_selectedAlertView.dataArray = self->_zhuJiaoArray;
        [self->_selectedAlertView reloadData];
        
    } else {
        NSDictionary *parama = @{@"name":@"",
                                 @"pageIndex":@"0",
                                 @"pageSize":@"1000"};
        [MBProgressHUD mj_showMessage:nil toView:_selectedAlertView];
        [SYRequestAPI sy_getClassList:parama success:^(id  _Nonnull responseObject) {
            //        NSLog(@"得到老师班级 %@",responseObject);
            NSArray *array = [responseObject objectForKey:@"data"];
            for (NSDictionary *dic in array) {
                FenXiaoZhuJiaoModel *model = [[FenXiaoZhuJiaoModel alloc] init];
                model.name = [dic nilObjectForKey:@"name"];
                model.classId = [dic nilObjectForKey:@"id"];
                [self->_zhuJiaoArray addObject:model];
                
            }
            self->_selectedAlertView.dataArray = self->_zhuJiaoArray;
            [self->_selectedAlertView reloadData];
            [MBProgressHUD mj_hideHUDForView:self->_selectedAlertView];
        } fail:^(NSError *error) {
            [MBProgressHUD mj_hideHUDForView:self->_selectedAlertView];
        }];
    }
    
    
    
}
#pragma mark - 设置辅导类型
- (void)setFuDaoTypeRequest{
    NSDictionary *parama = @{};
    __weak typeof(self) weakSelf = self;
    [SYRequestAPI fd_TutorTutorTutorType:parama success:^(id responseObject) {
        //NSLog(@"得到辅导类型  %@",responseObject);
        NSDictionary *dic = [responseObject objectForKey:@"data"];
        NSArray *array = [dic objectForKey:@"dataTypes"];
        self->maxNumOfFuDao = [[dic objectForKey:@"maxCount"] intValue];
        for (NSDictionary *d in array) {
            FuDaoLeiXingObject *model = [FuDaoLeiXingObject yy_modelWithJSON:d];
            [self->_fuDaoTypeArray addObject:model];
        }
        
        if (weakSelf.isMessage) {//一键创班
            [weakSelf fuDaoYuanYou];
        }
        
        self->_fuDaoTimesArray = getFuDaoNumber(self->maxNumOfFuDao);
    } fail:^(NSError *error) {
        
    }];
}
#pragma mark - 设置辅导次数函数
NSMutableArray *getFuDaoNumber(int max){
    NSMutableArray *array = [NSMutableArray new];
    for (int i = 1;i<=max;i++) {
        [array addObject:[NSString stringWithFormat:@"%d",i]];
    }
    return array;
}
#pragma mark - 点击Ruturn
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
- (void)textViewDidBeginEditing:(UITextView *)textView{

}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self endEditing:YES];
    return YES;
}
#pragma mark - 键盘弹出
- (void)addNoticeForKebord{
    //监听事件键盘
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}
#pragma mark - keyboard

//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)note {
    //取出键盘最终的frame
    CGRect rect = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    editeView.text = _fuDaiContentTV.text;
    editeView.frame = CGRectMake(0, rect.origin.y-50, rect.size.width, 50);
    //取出键盘弹出需要花费的时间
//    CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];

}

//当键盘消失时调用
- (void)keyboardWillHide:(NSNotification *)note {
    //取出键盘弹出需要花费的时间
    double duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    _fuDaiContentTV.text = editeView.text;
    [editeView removeFromSuperview];
}
#pragma mark -添加编辑View
- (UITextView *)AddEditeView{
    editeView = [[UITextView alloc]init];
    editeView.frame = CGRectMake(0, self.frame.size.height,self.frame.size.width, 50);
    editeView.text = _fuDaiContentTV.text;
    [editeView becomeFirstResponder];
    editeView.layer.cornerRadius = 5;
    editeView.layer.masksToBounds = YES;
    editeView.layer.borderWidth = 1;
    editeView.delegate = self;
    editeView.layer.borderColor  =LINCOLOR.CGColor;
    return editeView;
}

@end
